package com.jiyun.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jiyun.client.RoomClient;
import com.jiyun.client.UserClient;
import com.jiyun.client.VisterClient;
import com.jiyun.entity.RepairRecord;
import com.jiyun.entity.Room;
import com.jiyun.pojo.MyResult;
import com.jiyun.service.IRepairRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("count")
public class CountController {


    @Autowired
    UserClient userClient;

    @Autowired
    VisterClient visterClient;

    @Autowired
    IRepairRecordService repairRecordService;

    @Autowired
    RoomClient roomClient;

    @RequestMapping("detail")
    public MyResult count(){

        /**
         * 1、学生人数---用户表中role是stu的人数
         * 2、访客人数
         * 3、处理中的报修数量
         * 4、room中currentNum为0的数量
         *
         * 5、统计每个宿舍的人数
         *
         */

        Integer stuNum = userClient.findStuNum();

        Integer allNum = visterClient.findAllNum();

        LambdaQueryWrapper<RepairRecord> repairRecordLambdaQueryWrapper = new LambdaQueryWrapper<>();
        repairRecordLambdaQueryWrapper.eq(RepairRecord::getState,"处理中");
        int repairNum = repairRecordService.count(repairRecordLambdaQueryWrapper);

        Integer noStuRoomNum = roomClient.findNoStuRoomNum();

        List<Room> roomNumCount = roomClient.findAll();

        HashMap hashMap = new HashMap();
        hashMap.put("stuNum",stuNum);
        hashMap.put("allNum",allNum);
        hashMap.put("repairNum",repairNum);
        hashMap.put("noStuRoomNum",noStuRoomNum);
        hashMap.put("roomNumCount",roomNumCount);


        return MyResult.OK(hashMap);

    }


}
